package cn.dengta.webapp.trade.dao;

import java.util.List;

import cn.dengta.webapp.base.dao.BaseDao;
import cn.dengta.webapp.trade.entity.UserLimit;
import org.apache.ibatis.annotations.*;

/**
 * Mapper 接口
 *
 * @author lgy
 * @since 2022-06-16
 */
public interface UserLimitDao extends BaseDao<UserLimit> {

	@Delete("DELETE FROM dt_user_limit WHERE id = #{id}")
	Integer deleteLimitById(@Param("id") Long id);

	@InsertProvider(type = UserLimitDaoProvider.class, method = "batchUserLimit")
	void batchUserLimit(@Param("list") List<UserLimit> limits);

	class UserLimitDaoProvider {

		public String batchUserLimit(@Param("list") List<UserLimit> limits) {
			StringBuilder sql = new StringBuilder(2048);
			sql.append("INSERT INTO dt_user_limit(user_id,type,biz_flag,start_date,end_date,remark,add_time, update_time) VALUES ");
			for (int i = 0; i < limits.size(); i++) {
				sql.append("(");
				sql.append("#{list[").append(i).append("].userId}").append(",");
				sql.append("#{list[").append(i).append("].type}").append(",");
				sql.append("#{list[").append(i).append("].bizFlag}").append(",");
				sql.append("#{list[").append(i).append("].startDate}").append(",");
				sql.append("#{list[").append(i).append("].endDate}").append(",");
				sql.append("#{list[").append(i).append("].remark}").append(",");
				sql.append("#{list[").append(i).append("].addTime}").append(",");
				sql.append("#{list[").append(i).append("].updateTime}");
				sql.append(")");
				if (i < limits.size() - 1) {
					sql.append(",");
				}
			}
			return sql.toString();
		}

	}

}
